package com.example.spring_blog_24_9_8.service;

import com.example.spring_blog_24_9_8.mapper.BlogMapper;
import com.example.spring_blog_24_9_8.mapper.UserMapper;
import com.example.spring_blog_24_9_8.model.Blog;
import com.example.spring_blog_24_9_8.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
 @Autowired
 private UserMapper userMapper;
 @Autowired
 private  BlogMapper blogMapper;

 public User getUserInfo(String username){
      return userMapper.selectByName(username);
 }

 public User selectById(Integer Id){
     return  userMapper.selectById(Id);
 }

    public User selectAuthorByBlogId(Integer blogId) {
        //1. 根据博客ID, 获取作者ID
        //2. 根据作者ID, 获取作者信息
        Blog blog = blogMapper.selectById(blogId);
        if (blog==null && blog.getUserId()<1){
            return null;
        }
        User user = userMapper.selectById(blog.getUserId());
        return user;
    }
}
